package com.loc;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import kotlin.jvm.internal.LongCompanionObject;

/* compiled from: Req.java */
/* loaded from: classes2.dex */
public final class fr {
    protected static String I;
    protected static String K;
    public String a = "1";
    protected short b = 0;
    protected String c = null;
    protected String d = null;
    protected String e = null;
    protected String f = null;
    protected String g = null;
    public String h = null;
    public String i = null;
    protected String j = null;
    protected String k = null;
    protected String l = null;
    protected String m = null;
    protected String n = null;
    protected String o = null;
    protected String p = null;
    protected String q = null;
    protected String r = null;
    protected String s = null;
    protected String t = null;
    protected String u = null;
    protected String v = null;
    protected String w = null;
    protected String x = null;
    protected String y = null;
    protected int z = 0;
    protected ArrayList<fa> A = new ArrayList<>();
    protected ArrayList<fa> B = new ArrayList<>();
    protected String C = null;
    protected String D = null;
    protected ArrayList<eg> E = new ArrayList<>();
    protected String F = null;
    protected String G = null;
    protected byte[] H = null;
    private byte[] Q = null;
    private int R = 0;
    protected String J = null;
    protected String L = null;
    protected String M = null;
    protected String N = null;
    protected int O = 0;
    private List<fc> S = null;
    private List<fa> T = Collections.synchronizedList(new ArrayList());
    final int P = 3;

    private static int a(String str, byte[] bArr, int i) {
        try {
        } catch (Throwable th) {
            ft.a(th, "Req", "copyContentWithByteLen");
            bArr[i] = 0;
        }
        if (TextUtils.isEmpty(str)) {
            bArr[i] = 0;
            return i + 1;
        }
        byte[] bytes = str.getBytes("GBK");
        int length = bytes.length;
        if (length > 127) {
            length = 127;
        }
        bArr[i] = (byte) length;
        int i2 = i + 1;
        System.arraycopy(bytes, 0, bArr, i2, length);
        return i2 + length;
    }

    private static void a(fa faVar, List<fa> list) {
        if (faVar == null || list == null) {
            return;
        }
        int size = list.size();
        if (size == 0) {
            list.add(faVar);
            return;
        }
        long j = LongCompanionObject.MAX_VALUE;
        int i = 0;
        int i2 = -1;
        int i3 = -1;
        while (true) {
            if (i >= size) {
                i2 = i3;
                break;
            }
            fa faVar2 = list.get(i);
            if (faVar.c() == null || !faVar.c().equals(faVar2.c())) {
                j = Math.min(j, faVar2.t);
                if (j == faVar2.t) {
                    i3 = i;
                }
                i++;
            } else if (faVar.s != faVar2.s) {
                faVar2.t = faVar.t;
                faVar2.s = faVar.s;
            }
        }
        if (i2 >= 0) {
            if (size < 3) {
                list.add(faVar);
            } else if (faVar.t <= j || i2 >= size) {
            } else {
                list.remove(i2);
                list.add(faVar);
            }
        }
    }

    private void a(ArrayList<fa> arrayList, ArrayList<fa> arrayList2) {
        if (arrayList2 != null && arrayList2.size() > 0) {
            Iterator<fa> it = arrayList2.iterator();
            while (it.hasNext()) {
                fa next = it.next();
                if (next.r && next.n) {
                    a(next, this.T);
                    return;
                }
            }
        }
        if (arrayList == null || arrayList.size() <= 0) {
            return;
        }
        a(arrayList.get(0), this.T);
    }

    /* JADX WARN: Code restructure failed: missing block: B:5:0x000d, code lost:
        if (r0.length != 6) goto L3;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    private byte[] a(java.lang.String r7) {
        /*
            r6 = this;
            java.lang.String r0 = ":"
            java.lang.String[] r0 = r7.split(r0)
            r1 = 6
            byte[] r2 = new byte[r1]
            r3 = 0
            if (r0 == 0) goto Lf
            int r4 = r0.length     // Catch: java.lang.Throwable -> L3e
            if (r4 == r1) goto L1b
        Lf:
            java.lang.String[] r0 = new java.lang.String[r1]     // Catch: java.lang.Throwable -> L3e
            r4 = 0
        L12:
            if (r4 >= r1) goto L1b
            java.lang.String r5 = "0"
            r0[r4] = r5     // Catch: java.lang.Throwable -> L3e
            int r4 = r4 + 1
            goto L12
        L1b:
            r1 = 0
        L1c:
            int r4 = r0.length     // Catch: java.lang.Throwable -> L3e
            if (r1 >= r4) goto L54
            r4 = r0[r1]     // Catch: java.lang.Throwable -> L3e
            int r4 = r4.length()     // Catch: java.lang.Throwable -> L3e
            r5 = 2
            if (r4 <= r5) goto L30
            r4 = r0[r1]     // Catch: java.lang.Throwable -> L3e
            java.lang.String r4 = r4.substring(r3, r5)     // Catch: java.lang.Throwable -> L3e
            r0[r1] = r4     // Catch: java.lang.Throwable -> L3e
        L30:
            r4 = r0[r1]     // Catch: java.lang.Throwable -> L3e
            r5 = 16
            int r4 = java.lang.Integer.parseInt(r4, r5)     // Catch: java.lang.Throwable -> L3e
            byte r4 = (byte) r4     // Catch: java.lang.Throwable -> L3e
            r2[r1] = r4     // Catch: java.lang.Throwable -> L3e
            int r1 = r1 + 1
            goto L1c
        L3e:
            r0 = move-exception
            java.lang.String r7 = java.lang.String.valueOf(r7)
            java.lang.String r1 = "getMacBa "
            java.lang.String r7 = r1.concat(r7)
            java.lang.String r1 = "Req"
            com.loc.ft.a(r0, r1, r7)
            java.lang.String r7 = "00:00:00:00:00:00"
            byte[] r2 = r6.a(r7)
        L54:
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: com.loc.fr.a(java.lang.String):byte[]");
    }

    private void b() {
        String[] strArr = new String[27];
        strArr[0] = this.a;
        strArr[1] = this.c;
        strArr[2] = this.d;
        strArr[3] = this.e;
        strArr[4] = this.f;
        strArr[5] = this.g;
        strArr[6] = this.h;
        strArr[7] = this.i;
        strArr[8] = this.l;
        strArr[9] = this.m;
        strArr[10] = this.n;
        strArr[11] = this.o;
        strArr[12] = this.p;
        strArr[13] = this.q;
        strArr[14] = this.r;
        strArr[15] = this.s;
        strArr[16] = this.t;
        strArr[17] = this.u;
        strArr[18] = this.v;
        strArr[19] = this.w;
        strArr[20] = this.x;
        strArr[21] = this.D;
        strArr[22] = this.F;
        strArr[23] = this.G;
        strArr[24] = I;
        strArr[25] = this.M;
        strArr[26] = this.N;
        for (int i = 0; i < 27; i++) {
            if (TextUtils.isEmpty(strArr[i])) {
                strArr[i] = "";
            }
        }
        if (TextUtils.isEmpty(this.j) || (!"0".equals(this.j) && !"2".equals(this.j))) {
            this.j = "0";
        }
        if (TextUtils.isEmpty(this.k) || (!"0".equals(this.k) && !"1".equals(this.k))) {
            this.k = "0";
        }
        if (TextUtils.isEmpty(this.y) || (!"1".equals(this.y) && !"2".equals(this.y))) {
            this.y = "0";
        }
        if (!fb.a(this.z)) {
            this.z = 0;
        }
        if (this.H == null) {
            this.H = new byte[0];
        }
    }

    public final void a(Context context, boolean z, boolean z2, fb fbVar, fh fhVar, ConnectivityManager connectivityManager, String str, fd fdVar) {
        String str2;
        String str3;
        String str4;
        NetworkInfo networkInfo;
        String str5;
        String str6;
        ArrayList<eg> arrayList;
        int i;
        String f = l.f(context);
        int d = gb.d();
        this.J = str;
        this.S = null;
        if (z2) {
            str2 = "api_serverSDK_130905";
            str3 = "S128DF1572465B890OE3F7A13167KLEI";
        } else {
            str2 = "UC_nlp_20131029";
            str3 = "BKZCHMBBSSUK7U8GLUKHBB56CCFF78U";
        }
        String str7 = str3;
        String str8 = str2;
        StringBuilder sb = new StringBuilder();
        int g = fbVar.g();
        int h = fbVar.h();
        TelephonyManager i2 = fbVar.i();
        ArrayList<fa> c = fbVar.c();
        ArrayList<fa> d2 = fbVar.d();
        ArrayList<eg> e = fhVar.e();
        String str9 = h == 2 ? "1" : "0";
        if (i2 != null) {
            if (TextUtils.isEmpty(ft.g)) {
                try {
                    ft.g = o.k();
                } catch (Throwable th) {
                    ft.a(th, "Aps", "getApsReq part4");
                }
            }
            str4 = "1";
            if (TextUtils.isEmpty(ft.g) && Build.VERSION.SDK_INT < 29) {
                ft.g = "888888888888888";
            }
            if (TextUtils.isEmpty(ft.h)) {
                try {
                    ft.h = o.n();
                } catch (SecurityException unused) {
                } catch (Throwable th2) {
                    ft.a(th2, "Aps", "getApsReq part2");
                }
            }
            if (TextUtils.isEmpty(ft.h) && Build.VERSION.SDK_INT < 29) {
                ft.h = "888888888888888";
            }
        } else {
            str4 = "1";
        }
        try {
            networkInfo = connectivityManager.getActiveNetworkInfo();
        } catch (Throwable th3) {
            ft.a(th3, "Aps", "getApsReq part");
            networkInfo = null;
        }
        boolean a = fhVar.a(connectivityManager);
        if (gb.a(networkInfo) != -1) {
            str5 = gb.a(connectivityManager);
            str6 = a ? "2" : str4;
        } else {
            str5 = "";
            str6 = str5;
        }
        if ((g & 4) != 4 || d2.isEmpty()) {
            this.B.clear();
        } else {
            this.B.clear();
            this.B.addAll(d2);
        }
        this.A.clear();
        this.A.addAll(c);
        StringBuilder sb2 = new StringBuilder();
        if (fhVar.k()) {
            if (a) {
                fg m = fhVar.m();
                if (fhVar.a(m)) {
                    sb2.append(m.a());
                    sb2.append(",");
                    int c2 = m.c();
                    if (c2 < -128 || c2 > 127) {
                        c2 = 0;
                    }
                    sb2.append(c2);
                    sb2.append(",");
                    String b = m.b();
                    try {
                        i = b.getBytes("UTF-8").length;
                    } catch (Exception unused2) {
                        i = 32;
                    }
                    if (i >= 32) {
                        b = "unkwn";
                    }
                    sb2.append(b.replace("*", "."));
                }
            }
            if (e != null && (arrayList = this.E) != null) {
                arrayList.clear();
                this.E.addAll(e);
            }
        } else {
            fhVar.g();
            ArrayList<eg> arrayList2 = this.E;
            if (arrayList2 != null) {
                arrayList2.clear();
            }
        }
        this.b = (short) 0;
        if (!z) {
            this.b = (short) (2 | 0);
        }
        this.c = str8;
        this.d = str7;
        this.f = Build.MODEL;
        this.g = "android" + Build.VERSION.RELEASE;
        this.h = gb.b(context);
        this.i = str9;
        this.j = "0";
        this.k = "0";
        this.l = "0";
        this.m = "0";
        this.n = "0";
        this.o = f;
        this.p = ft.g;
        this.q = ft.h;
        this.s = String.valueOf(d);
        this.t = gb.i(context);
        this.v = "6.4.2";
        this.w = null;
        this.u = "";
        this.x = str5;
        this.y = str6;
        this.z = g;
        this.C = fbVar.l();
        this.F = fh.p();
        this.D = sb2.toString();
        this.O = (int) ((gb.b() - fhVar.q()) / 1000);
        try {
            if (TextUtils.isEmpty(I)) {
                I = o.f(context);
            }
        } catch (Throwable unused3) {
        }
        try {
            if (TextUtils.isEmpty(K)) {
                K = o.a(context);
            }
        } catch (Throwable unused4) {
        }
        try {
            if (TextUtils.isEmpty(this.M)) {
                this.M = o.f();
            }
        } catch (Throwable unused5) {
        }
        try {
            if (TextUtils.isEmpty(this.N)) {
                this.N = o.e(context);
            }
        } catch (Throwable unused6) {
        }
        try {
            this.S = fdVar.a(this.B, this.E);
            a(this.A, this.B);
        } catch (Throwable th4) {
            th4.printStackTrace();
        }
        sb.delete(0, sb.length());
        sb2.delete(0, sb2.length());
    }

    /* JADX WARN: Can't wrap try/catch for region: R(46:12|13|14|(17:277|(1:279)(1:381)|280|(7:282|(1:284)(1:358)|285|(1:287)(1:357)|288|(1:290)(1:356)|291)(12:(11:360|(1:362)(1:380)|363|(1:365)(1:379)|366|(1:368)(1:378)|369|(1:371)(1:377)|372|(1:374)(1:376)|375)|293|(1:295)(1:355)|(1:297)|298|(1:300)(1:353)|301|(1:303)|304|(1:306)|307|(2:309|(2:311|312)(3:313|(11:315|(1:317)(1:348)|318|(1:320)(1:347)|321|(1:323)(1:346)|324|(1:326)|327|(2:342|343)(8:329|(1:331)(1:341)|332|(1:334)|335|(1:337)|338|339)|340)|349))(2:350|(2:352|312)))|292|293|(0)(0)|(0)|297|298|(0)(0)|301|(0)|304|(0)|307|(0)(0))(1:17)|18|(40:22|23|24|25|(1:273)(4:28|(6:30|(3:87|(1:89)|90)(3:36|(3:38|(1:40)|41)(2:81|(3:83|(1:85)|86))|42)|43|(1:45)|46|(3:67|(1:78)(5:69|(1:71)|(1:73)|74|(3:76|62|63)(1:77))|64)(3:52|(6:56|(1:58)|(1:60)|61|62|63)|64))|91|92)|93|(1:272)(14:97|98|99|100|101|(1:103)|104|105|106|(5:267|(1:269)|109|(2:111|112)|114)|108|109|(0)|114)|115|(1:117)(7:234|(1:236)(1:266)|(1:238)|239|(10:241|242|243|244|245|(1:247)(2:259|(1:261))|248|(1:258)(1:252)|(2:254|255)(1:257)|256)|264|265)|118|119|120|(1:122)(3:226|(1:228)|(1:230)(28:231|232|124|125|126|(1:128)|129|130|(3:219|220|221)|132|133|134|135|136|137|138|139|(1:141)(1:214)|142|(1:144)|145|(5:147|(1:149)(1:186)|150|(5:153|154|(8:157|(4:164|(3:166|(1:168)|169)(2:172|(3:174|(1:176)|177))|170|171)|178|(1:180)|181|170|171|155)|182|183)|152)|187|(4:189|(1:191)(1:207)|192|(3:194|(6:197|(1:199)|200|(2:202|203)(1:205)|204|195)|206))|208|(1:210)|211|212))|123|124|125|126|(0)|129|130|(0)|132|133|134|135|136|137|138|139|(0)(0)|142|(0)|145|(0)|187|(0)|208|(0)|211|212)|276|25|(0)|273|93|(1:95)|272|115|(0)(0)|118|119|120|(0)(0)|123|124|125|126|(0)|129|130|(0)|132|133|134|135|136|137|138|139|(0)(0)|142|(0)|145|(0)|187|(0)|208|(0)|211|212) */
    /* JADX WARN: Code restructure failed: missing block: B:275:0x06f3, code lost:
        r7[r8] = 0;
        r2 = 1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:287:0x0726, code lost:
        r2 = 2;
        r8 = r8 + 2;
     */
    /* JADX WARN: Removed duplicated region for block: B:124:0x031c  */
    /* JADX WARN: Removed duplicated region for block: B:137:0x035e A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:205:0x0556  */
    /* JADX WARN: Removed duplicated region for block: B:226:0x05ce A[Catch: all -> 0x05de, TRY_LEAVE, TryCatch #10 {all -> 0x05de, blocks: (B:209:0x0564, B:218:0x059d, B:224:0x05af, B:226:0x05ce, B:211:0x057a, B:214:0x0587), top: B:381:0x0564 }] */
    /* JADX WARN: Removed duplicated region for block: B:234:0x0613  */
    /* JADX WARN: Removed duplicated region for block: B:235:0x0619  */
    /* JADX WARN: Removed duplicated region for block: B:267:0x06d1 A[Catch: all -> 0x06f3, TryCatch #3 {all -> 0x06f3, blocks: (B:265:0x06cd, B:267:0x06d1, B:268:0x06d4, B:272:0x06e0, B:273:0x06e5), top: B:369:0x06cd }] */
    /* JADX WARN: Removed duplicated region for block: B:268:0x06d4 A[Catch: all -> 0x06f3, TryCatch #3 {all -> 0x06f3, blocks: (B:265:0x06cd, B:267:0x06d1, B:268:0x06d4, B:272:0x06e0, B:273:0x06e5), top: B:369:0x06cd }] */
    /* JADX WARN: Removed duplicated region for block: B:26:0x00f0  */
    /* JADX WARN: Removed duplicated region for block: B:27:0x00fb  */
    /* JADX WARN: Removed duplicated region for block: B:280:0x0706 A[Catch: all -> 0x0726, TryCatch #5 {all -> 0x0726, blocks: (B:278:0x06fe, B:280:0x0706, B:281:0x0710), top: B:372:0x06fe }] */
    /* JADX WARN: Removed duplicated region for block: B:294:0x073e  */
    /* JADX WARN: Removed duplicated region for block: B:295:0x0740  */
    /* JADX WARN: Removed duplicated region for block: B:298:0x074f  */
    /* JADX WARN: Removed duplicated region for block: B:301:0x0769  */
    /* JADX WARN: Removed duplicated region for block: B:30:0x0108  */
    /* JADX WARN: Removed duplicated region for block: B:340:0x0871  */
    /* JADX WARN: Removed duplicated region for block: B:358:0x091c  */
    /* JADX WARN: Removed duplicated region for block: B:370:0x0718 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:44:0x0164  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x0205  */
    /* JADX WARN: Removed duplicated region for block: B:69:0x0210  */
    /* JADX WARN: Removed duplicated region for block: B:72:0x0215 A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:76:0x0224  */
    /* JADX WARN: Removed duplicated region for block: B:77:0x0237  */
    /* JADX WARN: Removed duplicated region for block: B:80:0x0242  */
    /* JADX WARN: Removed duplicated region for block: B:83:0x0247  */
    /* JADX WARN: Removed duplicated region for block: B:86:0x0255  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final byte[] a() {
        /*
            Method dump skipped, instructions count: 2385
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.loc.fr.a():byte[]");
    }
}
